from datetime import datetime, timezone
from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column, column_property
from sqlalchemy.sql import expression

from .base import Base


class User(Base):
    __tablename__ = "user"

    id: Mapped[int] = mapped_column(primary_key=True)
    username: Mapped[str] = mapped_column(String(32), nullable=False)
    hashed_password: Mapped[bytes]
    email: Mapped[str] = mapped_column(nullable=False, unique=True)
    active: Mapped[bool] = mapped_column(
        server_default=expression.false(),
        nullable=False,
    )
    is_superuser: Mapped[bool] = mapped_column(
        server_default=expression.false(),
        nullable=False,
    )

    firstname: Mapped[str] = mapped_column(String(50), nullable=True)
    lastname: Mapped[str] = mapped_column(String(50), nullable=True)
    fullname: Mapped[str] = column_property(firstname + " " + lastname)
    phone: Mapped[str] = mapped_column(String(11), nullable=True)
    registered_at: Mapped[datetime] = mapped_column(default=datetime.now(timezone.utc))

    # class Config:
    #     fields = {
    #         "id",
    #         "username",
    #         "hashed_password",
    #         "email",
    #         "firstname",
    #         "lastname",
    #         "fullname",
    #         "phone",
    #     }
